package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.*;

@Controller
public class HelloController {

    /**
     * 展示普通数据
     * @param model
     * @return
     */
    @GetMapping("/basic")
    public String testHello(Model model) {

        // 向页面传入纯文本参数
        model.addAttribute("name","大狗子");

        // 向页面传入对象
        Student stu = new Student();
        stu.setName("二狗子");
        stu.setAge(18);

        model.addAttribute("stu",stu);

        return "01-basic";
    }

    @GetMapping("/list")
    public String list(Model model) {

        // 向页面展示List数据
        Student stu1 = new Student();
        stu1.setName("大狗子");
        stu1.setAge(18);
        stu1.setMoney(20.22f);
        stu1.setBirthday(new Date());

        Student stu2 = new Student();
        stu2.setBirthday(new Date());
        stu2.setName("二狗子");
        stu2.setAge(20);
        stu2.setMoney(55.22f);

        List<Student> list = new ArrayList<>();
        list.add(stu1);
        list.add(stu2);

        model.addAttribute("stus",list);


        // 向页面传输map对象
        Map<String, Student> map = new HashMap<>();
        map.put("stu1", stu1);
        map.put("stu2", stu2);

        model.addAttribute("map",map);

        return "02-list";

    }

}
